package br.com.assessoriaesportiva.service;

import java.util.List;
import java.util.Map;
import br.com.assessoriaesportiva.dao.CrudDAO;
import br.com.assessoriaesportiva.regradenegocio.RegraNegocioException;
import br.com.assessoriaesportiva.regradenegocio.RegrasNegocio;

public abstract class CrudServiceImp<T> implements CrudService<T> {

	@Override
	public Long novo(T t) throws RegraNegocioException {
		if(!isExiste(t))
			return getDao().novo(t);
		else
			throw new RegraNegocioException(RegrasNegocio.CadastroRepetido);
	}
	
	@Override
	public void atualizar(T t) {
		getDao().atualizar(t);
	}

	@Override
	public void excluir(T t) throws Exception {
		getDao().excluir(t);
	}

	@Override
	public T buscarPorID(long id) {
		return getDao().buscarPorId(id);
	}
		
	public abstract CrudDAO<T> getDao();
		
	public abstract boolean isExiste(T t);
	
	@Override
	public List<T> buscarPorNQ(final String namedQuery, final Map<String, Object> params) {
		return getDao().buscarPorNQ(namedQuery, params);
		
	}
	
}
